#!/usr/bin/env php
<?php
//艺考专业详情爬虫
//php schoopl-major-spider.php start
require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/bootstrap/database.php';
require_once __DIR__.'/bootstrap/arguments.php';

use App\Workers\SchoolMajorSpiderWorker;
use Workerman\Worker;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// 解析命令行参数
$args = parseArguments($argv);
$options = $args['options'];

$baseUrl = dirname(__DIR__).'/college';

// 创建Worker
$worker = new Worker();
$worker->name = 'SchoolMajorSpiderSpiderWorker';
$worker->count = 1;
$worker->reloadable = true;
$worker->user = '';
$worker::$stdoutFile = $baseUrl . '/storage/tmp/school-major-worker.stdout.log';
$worker::$pidFile = $baseUrl . '/storage/tmp/school-major-worker.pid';
$worker::$logFile = $baseUrl . '/storage/tmp/school-major-worker.log';

// 确保logs目录存在
$logDir = dirname(__DIR__).'/college/storage/logs';
if (!is_dir($logDir)) {
    mkdir($logDir, 0755, true);
}

// 初始化日志服务
$logger = new Logger('艺考院校开设专业采集Worker');
$logger->pushHandler(new StreamHandler($logDir.'/school-major-worker.log'));

// 初始化Worker
SchoolMajorSpiderWorker::run($worker, $options);

Worker::runAll();
